<!doctype html>
<html><head>
	<meta charset="utf-8">
	<title>知识库资料</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" type="image/x-icon" href="/static/img/favicon.ico">
	
	<!-- jQuery-->
	<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>

	<!-- layui-->
	<link rel="stylesheet" href="/static/plugins/layui/2.7.6/css/layui.css" media="all">
	<script src="/static/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>
	
	<!-- common -->
	<link rel="stylesheet" href="/static/admin/css/common.css" media="all" />
	<link rel="stylesheet" href="/static/admin/css/mini-ease.css" media="all" />
	
	<!-- iconfont -->
	<link rel="stylesheet" href="/static/css/icon/iconfont.css" media="all" />
	
</head>
<style>

	.layui-table-header .layui-table-cell{
		height:auto;
		overflow:visible;
		text-overflow:inherit;
		white-space:normal;
		word-break: break-all;
		text-align: center;
	}
	.layui-table-cell{
		display: inline-block;!important
		line-height: 15px;
		margin-left: 15px;
		margin-right: 15px;
		padding-top:15px;
	}
	.back-btn{
		border: none;
		font-size: 15px;
	}
	.title-view{
		margin-bottom: 10px;
	}
	.btn-view-search{
		float: right;
	}
	.layui-select-title .layui-unselect{
		background-color: white !important;
	}
	.layui-form-select{
		margin-top: 2px;
	}
</style>
<body style="padding: 10px 0 0 10px;">
	<!-- 标题 -->
	<div class="title-view">
		<div style="float: left;margin-left: 10px;">
			<button type="button" class="layui-btn layui-btn-sm layui-btn-primary back-btn" onclick="backPage()">
				<i class="layui-icon layui-icon-left"></i> 返回
			</button>
		</div>
		<div style="padding-top: 2px;">
			<span style="padding-left:10px;line-height: 25px;font-size: 18px;">[[${dto.name}]]</span>
		</div>
	</div>

	<!-- 列表 -->
	<div class="layui-row layui-col-space5" style="width:100%;">

		<div class="layui-col-md10" id="id_panel_left_grid">
			<div class="layui-panel" style="overflow: auto; padding-top: 0.2rem;">
				<div class="mid-content">
					
					<table class="layui-hide" id="main_table" lay-filter="main_table"></table>
					 
					<script type="text/html" id="toolbarDemo">
						<div class="layui-row" style="height: 40px;">
							<div class="layui-col-xs12">
								<button type="button" class="layui-btn layui-bg-blue layui-btn-sm btn-view"  lay-on="add-data">
									<i class="layui-icon layui-icon-add-1 layui-font-12"></i> 新增内容
								</button>
								<button type="button" class="layui-btn layui-bg-blue layui-btn-sm btn-view"  lay-on="upload-data">
									<i class="layui-icon layui-icon-upload layui-font-12"></i> 文件导入
								</button>
								<button type="button" class="layui-btn layui-btn-sm btn-view"  lay-on="look-type">
									<i class="layui-icon layui-icon-list layui-font-12"></i> 查看分类
								</button>
								<button type="button" class="layui-btn layui-bg-red layui-btn-sm btn-view"  lay-event="delList">
									<i class="layui-icon layui-icon-delete layui-font-12"></i> 删除
								</button>
							</div>
							<!--
							<div class="layui-col-xs2">
								<select style="background-color: white;height: 30px;padding-top: 3px;">
									<option value="">请选择分类</option>
									<option value="BBB">选项 B</option>
									<option value="CCC">选项 C</option>
								</select>
							</div>
							<div class="layui-col-xs7" style="height: 40px;margin-left: 15px;">
								<div style="width: 300px;height: 0px;padding-top: 2px;">
									<div style="width: 260px;"><input type="text" placeholder="搜索文档内容" class="layui-input" ></div>
									<div style="width: 40px;float: right;position: relative;top: -30px;height: 30px;background-color: white;text-align: center;border-left-color: gray;cursor: pointer;">
										<i class="layui-icon layui-icon-search"></i>
									</div>
								</div>
							</div>
							-->
						</div>
					</script>
					<script type="text/html" id="templet_index_no">{{d.LAY_TABLE_INDEX+1}}</script>
				</div>
			</div>
		</div>

		<!-- 搜索面板【start】 -->
		<th:block th:include="include/search :: searchHTML"/>
		<th:block th:include="include/search :: searchJS"/>
		<!-- 搜索面板【end】 -->


		<input type="hidden" name="id" id="id" value=""><!--知识库id-->
	</div>
	<script type="text/javascript">
		$('#id').val('[(${dto.id})]');
		layui
				.extend({optimizeSelectOption: '/static/plugins/layui/extends/optimizeSelectOption/optimizeSelectOption'})
				.use(['form', 'element', 'table', 'dropdown', 'optimizeSelectOption', 'util', 'laydate'], function(){
					var element = layui.element;
					var table = layui.table;
					var dropdown = layui.dropdown;
					var form = layui.form;
					var util = layui.util;
					var $ = layui.jquery;
					var laydate = layui.laydate;


					var cols =[ //表头
						[
							{title: '', type: 'checkbox',  unresize: true, width: '40'},
							{title: '序号',   align:"center",type:"numbers"},
							{title: '分类', width: '100' , field:'typeName', align:"center"},
							{title: '内容', width:700, field:'information', align:"left",templet:
										function(d){
											return '<span style="white-space: pre-line;text-align: left; line-height: 20px;height: 100px;width: 100%;">'+(d.information)+'</span>';
										}
							},
							{title: '更新人', width: '120' , field:'userName', align:"center"},
							{title: '更新时间', width: '150' , field:'updateTime', align:"center"},
							{title: '操作', width: '300' , align:"center",templet:
										function(d){
											return '<button type="button" class="layui-btn layui-btn-sm" onclick="toUpdate(\''+d.id+'\',\''+d.sectionId+'\');"><i class="layui-icon layui-icon-edit layui-font-12"></i> 修改</button>'
													+'<button type="button" class="layui-btn layui-btn-sm" onclick="toUpdateBySection(\''+d.id+'\',\''+d.sectionId+'\',\''+d.baseId+'\');"><i class="layui-icon layui-icon-edit layui-font-12"></i> 按分段修改</button>'
													+'<button type="button" class="layui-btn layui-bg-red layui-btn-sm" onclick="toDel(\''+d.id+'\');"><i class="layui-icon layui-icon-delete layui-font-12"></i> 删除</button>';
										}
							},
						]
					];
					// 创建渲染实例
					table.render({
						elem: '#main_table'
						,url:'/api/inter/knowledgeList/search' // 此处为静态模拟数据，实际使用时需换成真实接口
						,toolbar: '#toolbarDemo'
						,defaultToolbar: [ 'filter',{
							title: '刷新页面'
							,layEvent: 'LAYTABLE_REFRESH'
							,icon: 'layui-icon-refresh'
						}]
						,height: window.innerHeight - 90 // 最大高度减去其他容器已占有的高度差
						,limit : 20
						,limits : [20,50,200,500]
						,where: getConds()//{id:'[(${dto.id})]'}display: inline-block;
						,cellMinWidth: 95
						,lineStyle :'height: 100px;margin-top:10px;margin-bottom:10px;padding-left:5px;padding-right:5px;display: flex; align-items: center;justify-content: center;'
						,page: true
						,request: {
							pageName: 'page',
							limitName: 'size'
						}
						//,skin: 'row'
						,even: true // 开启隔行背景
						,skin: 'grid'//设置表格边框风格
						,cols:cols
						,done: function(res){
							console.log(res);
						}
						,error: function(res, msg){
							console.log(res, msg)
						}
					});

					var indexSearchForm = 0;
					// 工具栏事件
					table.on('toolbar(main_table)', function(obj){
						var id = obj.config.id;
						var checkStatus = table.checkStatus(id);
						var othis = lay(this);
						switch(obj.event){
							case 'LAYTABLE_REFRESH':
							{
								layer.confirm("确定刷新吗？",{
									btn: ['确定', '取消']
								}, function (index) {
									location.reload();
									layer.close(index);
								});
								break;
							}
							case 'delList':{
								console.log('del',checkStatus);
								isDelList(checkStatus.data);
							}
						};
					});


					//触发表格复选框选择
					table.on('checkbox(main_table)', function(obj){
						console.log(obj)
					});

					//触发表格单选框选择
					table.on('radio(main_table)', function(obj){
						console.log(obj)
					});

					// 行单击事件
					table.on('row(main_table)', function(obj){

					});
					// 行双击事件
					table.on('rowDouble(main_table)', function(obj){
						//lookDetail(obj.data.operateCompanyId)
						toDetail(obj.data.id,obj.data.sectionId);
					});


					// 普通事件
					util.on('lay-on', {
						//新增
						"add-data": function(){
							layer.open({
								title: '新增',
								type: 2,
								area: ['1000px', '600px'],
								content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseListAdd?id='+$('#id').val(),
								fixed: false, // 不固定
								maxmin: true,
								btnAlign: 'c',
							});
						},
						//查看分类
						"look-type":function(){
							layer.open({
								title: '分类管理',
								type: 2,
								area: ['1000px', '600px'],
								content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseListType?id='+$('#id').val(),
								fixed: false, // 不固定
								maxmin: true,
								btnAlign: 'c',
							});
						},
						//文件导入
						"upload-data":function(){
							layer.open({
								title: '知识库文件导入',
								type: 2,
								area: ['1000px', '600px'],
								content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseListUpload?baseId='+$('#id').val(),
								fixed: false, // 不固定
								maxmin: true,
								btnAlign: 'c',
							});
						},
						//批量删除
						//"delList": function(){

						//}
					})


				});


		$('body').on("mouseenter",".layui-table-body tr",function () {
			$(this).siblings().find("div").css("color","#142A48");
			$(this).find("div").css("color","#4DA1FF");
		});

		//跳转详情页
		function toDetail(id,sectionId) {
			layer.open({
				title: '详情',
				type: 2,
				area: ['1000px', '600px'],
				content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseListDetail?id='+id+'&sectionId='+sectionId,
				fixed: false, // 不固定
				maxmin: true,
				btnAlign: 'c',
			});
		}

		//跳转修改页
		function toUpdate(id,sectionId) {
			layer.open({
				title: '修改',
				type: 2,
				area: ['1000px', '600px'],
				content: '/web/eKnowAi/webEKnowAiController/knowledgeBaseListUpdate?id='+id+'&sectionId='+sectionId,
				fixed: false, // 不固定
				maxmin: true,
				btnAlign: 'c',
			});
		}

		//跳转按分段修改页
		function toUpdateBySection(id,sectionId,baseId) {
			layer.open({
				title: '修改',
				type: 2,
				area: ['1000px', '600px'],
				content: '/web/eKnowAi/webEKnowAiController/knowledgeListUpdateBySection?id='+id+'&sectionId='+sectionId+'&baseId='+baseId,
				fixed: false, // 不固定
				maxmin: true,
				btnAlign: 'c',
			});
		}

		//删除
		function toDel(id) {
			var loadIndex = layer.confirm('确定要删除该内容?', {icon: 3}, function () {
				//点击确定的回调
				layer.close(loadIndex);
				layer.load(2);
				delYes(id);
			}, function () {});//点击取消的回调
		}

		//确定删除
		function delYes(id){
			$.ajax({
				url: '/api/inter/knowledgeList/delKnowledgeList',
				data: {
					'id':id
				},
				type: 'POST',
				async: true,
				success: function (result) {
					if(result.code=='SUCCESS'){
						layer.close();
						layer.msg("操作成功", {icon: 1});
						location.reload();
					}else {//失败
						layer.close();
						layer.msg("删除失败，请稍后再试！", {icon: 2});
					}
				},
				error: function () {
					layer.close();
					layer.msg("删除失败，请稍后再试！", {icon: 2});
				}
			});
		}


		//批量删除
		function isDelList(datas){
			if(datas.length == 0) {
				layer.alert('尚未选中数据');
				return;
			}
			var loadIndex = layer.confirm('确定要删除所选择的内容?', {icon: 3}, function () {

				//点击确定的回调
				/*
				layer.msg('请稍后', {
					icon: 16,
					shade: 0.01
				});

				 */
				layer.close(loadIndex);
				layer.load(2);
				delListYes(datas);
			}, function () {return false;});//点击取消的回调
		}

		//确定删除
		function delListYes(datas){
			var _list = [];
			for(var i=0;i<datas.length;i++){
				_list.push(datas[i].id);
			}
			$.ajax({
				url: '/api/inter/knowledgeList/delKnowledgeListByBatch',
				data: "list="+_list,
				type: 'POST',
				async: true,
				timeout: 60000,
				success: function (result) {
					if(result.code=='SUCCESS'){
						layer.closeAll();
						layer.msg("操作成功", {icon: 1});
						location.reload();
					}else {//失败
						layer.closeAll();
						layer.msg("删除失败，请稍后再试！", {icon: 2});
					}
				},
				error: function () {
					layer.closeAll();
					layer.msg("删除失败，请稍后再试！", {icon: 2});
				}
			});
			return false;
		}


		//返回按钮
		function backPage() {
			window.parent.layer.closeAll();
		}

		//搜索
		function getConds() {
			var conditions = [];
			conditions.push({'rangeType':'t_system', 'value': '[(${dto.id})]', 'field':'A.BaseId'});
			$(".bo-search-field").each(function(index, dom){
				var value = $(this).val();
				if (value != '') {
					conditions.push({'rangeType':$(this).attr('cond-range-type'), 'value': value, 'field':$(this).attr('name')});
				}
			});
			$(".bo-search-field-selector").each(function(index, dom){
				var value = $(this).val();
				if (value != '') {
					conditions.push({'rangeType':'t_system', 'value': value, 'field':$(this).attr('name')});
				}
			});
			return {'conditions': JSON.stringify(conditions)};
		}

		/**
		 * 重新加载表格
		 * @returns
		 */
		function reloadTableOfList() {
			layui.table.reload("main_table",{
				page: {curr: 1},
				where: getConds()
			})
		}

		//左边表格高度设置
		$(function() {
			$('#id_panel_left_grid').css('height', (window.innerHeight - 90) + 'px');
		});

	</script>

</body>
		
</html>